using System;
using System.Collections;
using System.Collections.Generic;
using Unity.Netcode;
using UnityEngine;

public class WallsTrigger : NetworkBehaviour
{
    [SerializeField]private Transform bulletsTransform;

    private void OnTriggerEnter(Collider other)
    {
        String tag = other.gameObject.tag;
        bool isOwner = other.transform.GetComponent<bullet>().IsOwner;
        Debug.Log($"{tag} , {isOwner}");
        if ("BULLET".Equals(tag) && isOwner)
        {
            Debug.Log($"bullet enter {other.transform.name}");
            DestroyBulletServerRpc();
        }
    }

    [ServerRpc]
    private void DestroyBulletServerRpc()
    {
        Transform bullet = bulletsTransform.GetChild(0);
        bullet?.GetComponent<NetworkObject>().Despawn();
        Destroy(bullet);
    }
}
